package cn.tedu.egnotice1113.controller;

import cn.tedu.egnotice1113.base.pojo.dto.NoticeAddParam;
import cn.tedu.egnotice1113.base.pojo.dto.NoticeListQuery;
import cn.tedu.egnotice1113.base.pojo.entity.Notice;
import cn.tedu.egnotice1113.base.pojo.vo.NoticeListVO;
import cn.tedu.egnotice1113.base.response.JsonResult;
import cn.tedu.egnotice1113.mapper.NoticeMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/notice/")
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @PostMapping("add")
    public JsonResult addNotice(@RequestBody NoticeAddParam noticeAddParam) {
        log.debug("noticeAddParam = "+ noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setUserId(1);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        notice.setIsDelete(0);
        noticeMapper.insertNotice(notice);
        return JsonResult.ok();

    }
@GetMapping("list")
    public JsonResult list(NoticeListQuery noticeListQuery){
        log.debug("资讯列表业务"+noticeListQuery);
    List<NoticeListVO> noticeListVOS=noticeMapper.selectNoticeByTitleAndType(noticeListQuery);
    return JsonResult.ok(noticeListVOS);
}

}
